package com.snail.cloud.servie.impl;

import com.snail.cloud.entities.Pay;
import com.snail.cloud.entities.PayDTO;
import com.snail.cloud.mapper.PayMapper;
import com.snail.cloud.servie.PayService;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 支付服务实现类
 *
 * @author snail
 * @date 2024/9/20
 */
@Service
public class PayServiceImpl implements PayService {

    @Resource
    private PayMapper payMapper;

    @Override
    public int add(Pay pay) {
        return payMapper.insertSelective(pay);
    }

    @Override
    public int delete(Integer id) {
        return payMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(PayDTO payDTO) {
        Pay pay = new Pay();
        BeanUtils.copyProperties(payDTO, pay);
        return payMapper.updateByPrimaryKeySelective(pay);
    }

    @Override
    public Pay get(Integer id) {
        if (id <= 0) throw new RuntimeException("id不能小于等于0");
        return payMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Pay> getAll() {
        return payMapper.selectAll();
    }
}
